package com.myown.structure.impl;

import com.myown.structure.Queue;

import java.util.LinkedList;

/**
 * 队列 <p>
 *
 * <tt>LinkedList</tt>实现 <p>
 *
 * @author lincky
 * @version v1.0.0
 * @time 2017.02.22 16:52
 */
public class LinkedQueue<E> extends AbstractCollection<E> implements Queue<E> {

    public LinkedQueue() {
        super(new LinkedList<E>());
    }

    @Override
    public E front() {
        return elements.get(0);
    }

    @Override
    public void enqueue(E item) {
        add(item);
    }

    @Override
    public E dequeue() {
        if (empty()) {
            throw new IndexOutOfBoundsException(UNDERFLOW_BOUND_MSG);
        }
        E head = get(0);
        remove(0);
        return head;
    }

    @Override
    public String toString() {
        return "LinkedQueue{" +
                "size=" + size() +
                ", linkedqueue=" + elements +
                '}';
    }

}
